Skip to main content

docker 编译

FROM golang:1.21.9-bullseye AS builder
WORKDIR /app

COPY go.mod ./
COPY go.sum ./

RUN go mod download

COPY main.go ./

RUN go build -o ping

FROM busybox:latest

WORKDIR /app

COPY --from=builder /app/ping .

EXPOSE 8080

CMD ["./ping"]


# 使用帮助
# 进入当前目录
# docker build -t httptest:latest .
# 记录版本 通过shell更新版本号
# current_datetime=$(date +"%Y.%m.%d-%H.%M")
# docker tag httptest:latest docker.io/aricksm/httptest:v$current_datetime
# docker push docker.io/aricksm/httptest:v$current_datetime
# docker tag httptest:latest docker.io/aricksm/httptest:latest
# docker push docker.io/aricksm/httptest:latest
# docker run -p 8080:8080 httptest:latest
# kubectl run httptest --image=docker.io/aricksm/httptest

FROM golang:1.15.15

WORKDIR $GOPATH/src
#COPY ../aicloud $GOPATH/src
#go build -o aicloud/api/uaa/build/uaa-api aicloud/api/uaa/main.go
#ENTRYPOINT ["go","build","-o","aicloud/api/uaa/build/uaa-api","aicloud/api/uaa/main.go"]
ENTRYPOINT ["/bin/bash"]

docker build -t gobuild .

docker run -it --name go-bulid-5 -v ~/go/src/aicloud:/go/src/aicloud gobuild

容器内 go build -o aicloud/api/uaa/build/uaa-api aicloud/api/uaa/main.godocker